from typing import List


def maxmiumScore(cards: List[int], cnt: int) -> int:
    cards.sort()
    len_cards = len(cards)
    if len_cards < cnt :
        return 0
    sum_cards = 0
    min_odd = float('inf')
    min_even = float('inf')
    for i in range(len_cards - 1,len_cards - cnt -1,-1):
        cur = cards[i]
        if cur % 2 == 1:
            min_odd = min(min_odd,cur)
        else:
            min_even = min(min_even,cur)
        sum_cards += cur
    if sum_cards % 2 == 0 :
        return sum_cards
    else:
        max_odd = -1
        max_even = -1
        for i in range (len_cards - cnt - 1 , -1 ,-1):
            cur = cards[i]
            if cur % 2 == 1:
                max_odd = max(max_odd,cur)
            else:
                max_even = max(max_even,cur)
        ans1,ans2 =0, 0
        if min_even != 1001 and max_odd != -1:
            ans1 = sum_cards -min_even + max_odd
        if min_odd != 1001 and max_even != -1:
            ans2 = sum_cards - min_odd + max_even
        return max(ans1,ans2)

def maxmiumScore1(cards: List[int], cnt: int) -> int:
    cards.sort(reverse=True)
    s = sum(cards[:cnt])
    if s % 2 == 0:
        return s
    def replace_sum(x : int) -> int:
        for v in cards[cnt:]:
            if v%2 != x %2 :
                return s -x + v 
        return 0
    x = cards[cnt -1]
    ans = replace_sum(x)
    for v in cards[cnt-1::-1]:
        if v % 2 != x %2:
            ans = max(ans,replace_sum(v))
            break
    return ans

